package com.corticon.client.validation;

import java.util.ArrayList;
import java.util.List;

import org.springframework.validation.Errors;

import com.corticon.client.model.NavigatePageInput;
import com.corticon.client.util.ValidationUtils;

public class NavigatePageValidator extends GenericHibernateValidator<NavigatePageInput> {
	public NavigatePageValidator(ValidationMessageFormatter validationMessageFormatter) {
		super.validationMessageFormatter = validationMessageFormatter;
	}

	@Override
	protected void complexValidate(Object object, Errors errors) {
		super.complexValidate(object, errors);
		NavigatePageInput validator = (NavigatePageInput) object;
		ValidationUtils validationUtils = new ValidationUtils();
		if (validator.getDialogId()!=null && validationUtils.checkLongCharacters(validator.getDialogId())==false){
			errors.rejectValue("dialogId", "E00001", "default message");
		}
		if (validator.getDialogId()!=null && validationUtils.checkLongCharacters(validator.getDialogInstanceId())==false){
			errors.rejectValue("dialogInstanceId", "E00001", "default message");
		}
		if (validator.getDialogId()!=null && validationUtils.checkLongCharacters(validator.getPageId())==false){
			errors.rejectValue("pageId", "E00001", "default message");
		}
		List<Character> vocabularyExcludedChars = new ArrayList<Character>();
		vocabularyExcludedChars.add('_');
		String[] nameArgs1 = { "dialogId" };
		commonCharactersValidate(validator.getDialogId(), vocabularyExcludedChars, errors, "dialogId", "E00001", nameArgs1, "default message");
		String[] nameArgs2 = { "dialogInstanceId" };
		commonCharactersValidate(validator.getDialogInstanceId(), vocabularyExcludedChars, errors, "dialogInstanceId", "E00001", nameArgs2, "default message");
		String[] nameArgs3 = { "navigation" };
		commonCharactersValidate(validator.getNavigation(), vocabularyExcludedChars, errors, "navigation", "E00001", nameArgs3, "default message");
		String[] nameArgs4 = { "pageId" };
		commonCharactersValidate(validator.getPageId(), vocabularyExcludedChars, errors, "pageId", "E00001", nameArgs4, "default message");		
	}
}
